#include "StdAfx.h"
#include "EffectManager.h"
#include "Root.h"

VAMPIRE_NAMESPACE_BEGIN

Effect* EffectManager::createEffect( const TString& fileName, const char* className )
{
	if (mRecMap[fileName])
	{
		return (Effect*)mRecMap[fileName];
	}

	Effect* effect = (Effect*)ClassFactory::getSingletonPtr()->create(className);

	LocationList::iterator it;
	LocationList::iterator itend = mLocationList.end();

	for (it = mLocationList.begin(); it != itend; ++it)
	{
		TString fullPath = (*it) + fileName;

		if (effect->initialise(fullPath))
		{
			effect->getTechnique();
			effect->bindHandles();
			mRecMap[fileName] = effect;
			return effect;
		}
	}

	SAFE_DELETE(effect);
	return NULL;
}

REGISTER_HELPER_IMPLEMENT(EffectManager);

VAMPIRE_NAMESPACE_END